package com.newsmanagement.controller.frontdesk;

import com.newsmanagement.common.Constants;
import com.newsmanagement.entity.NewsContentEntity;
import com.newsmanagement.entity.ReturnedMessages;
import com.newsmanagement.service.INewsContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author xbr
 * 2017.12.04 11:24
 * 后台系统 新闻内容管理
 */
@Controller
@RequestMapping("newsContentFront")
public class NewsContentFrontController {

    @Autowired
    private INewsContentService newsContentService;


    /**
     * 根据新闻内容id查询新闻内容详情
     * @param contentId 新闻内容id
     * @return
     * http://localhost:8080/newsContentFront/selectContent?contentId=2
     */
    @RequestMapping("selectContent")
    @ResponseBody
    public ReturnedMessages selectContent(
            @RequestParam( "contentId" ) Integer contentId
    ){

        return newsContentService.selectContent(contentId ,null ,null , Constants.INT_ONE);
    }


    /**
     * 根据新闻分类分页查询新闻列表
     * @param categoryId 新闻分类id
     * @return
     * http://localhost:8080/newsContentFront/selectContentByCategoryId?categoryId=10
     */
    @RequestMapping("selectContentByCategoryId")
    @ResponseBody
    public ReturnedMessages selectContentByCategoryId(
            @RequestParam( "categoryId" ) Integer categoryId
    ){

        return newsContentService.selectContent(null ,null ,categoryId , Constants.INT_THREE);
    }

    /**
     * 模糊查询
     * @param key 新闻分类id
     * @return
     * http://localhost:8080/newsContentFront/selectContentByKey?key=biao
     */
    @RequestMapping("selectContentByKey")
    @ResponseBody
    public ReturnedMessages selectContentByKey(
            @RequestParam( "key" ) String key
    ){

        return newsContentService.selectContent(null ,key ,null , Constants.INT_TWO);
    }



}
